
<?php
session_start();
include('ConnectBdd.php');

if(isset($_GET['id_Match'])){
    
    $match= $_GET['id_Match'];
}
else{
    $match= $_POST['id_Match'];
}

 if (isset($_SESSION["profil"]) and $_SESSION["profil"]=="equipe")
     {
     //Mise à jour des résultats
     if (isset($_POST['scoreS1Eq1'])){
    
    $reqInsertionScore="UPDATE volley_match SET Score_Set1_Dom='".$_POST['scoreS1Eq1']."', Score_Set1_Ext='".$_POST['scoreS1Eq2']."', Score_Set2_Dom='".$_POST['scoreS2Eq1']."', 
                            Score_Set2_Ext= '".$_POST['scoreS2Eq2']."', Score_Set3_Dom='".$_POST['scoreS3Eq1']."', Score_Set3_Ext='".$_POST['scoreS3Eq2']."', 
                            Score_Set4_Dom='".$_POST['scoreS4Eq1']."', Score_Set4_Ext='".$_POST['scoreS4Eq2']."', Score_Set5_Dom='".$_POST['scoreS5Eq1']."', Score_Set5_Ext='".$_POST['scoreS5Eq2']."', Date_Match='".$_POST['DateMatch']."'
                            WHERE Id_Match='".$match."'";

      $result = $connexion->query($reqInsertionScore);   
      echo '<h2>Mis à jour</h2>';

}
     
     
          $reqInfoEquipeDom="SELECT e1.Libelle_Equipe as dom, e2.Libelle_Equipe as ext, e1.Email_Equipe as MailEq1, e2.Email_Equipe as MailEq2, Date_Match,Libelle_Plage,Score_Set1_Dom,Score_Set2_Dom,Score_Set3_Dom,Score_Set4_Dom,Score_Set5_Dom
                                    ,Score_Set1_Ext,Score_Set2_Ext,Score_Set3_Ext,Score_Set4_Ext,Score_Set5_Ext, Date_Match 
                             FROM volley_match m, volley_equipe e1, volley_equipe e2, volley_plage p
                             WHERE e1.Id_Equipe = Id_Equipe_dom AND
                             e2.Id_Equipe = Id_Equipe_ext AND p.Id_Plage = m.Id_Plage AND
                             e1.Email_Equipe='".$_SESSION['mail']."' AND m.id_Match ='".$match."'";
          
          $result = $connexion->query($reqInfoEquipeDom);
            while($row=$result->fetch(PDO::FETCH_ASSOC))
                {
                    $Equipe1= $row["dom"];
                    $Equipe2= $row['ext'];
                    $Date=$row['Date_Match'];
                    $MailEquipe1 =$row['MailEq1'];
                    $MailEquipe2 =$row['MailEq2'];
                    $plage= $row['Libelle_Plage'];
                    $S1EqD=$row['Score_Set1_Dom'];
                    $S2EqD=$row['Score_Set2_Dom'];
                    $S3EqD=$row['Score_Set3_Dom'];
                    $S4EqD=$row['Score_Set4_Dom'];
                    $S5EqD=$row['Score_Set5_Dom'];
                    $S1EqE=$row['Score_Set1_Ext'];
                    $S2EqE=$row['Score_Set2_Ext'];
                    $S3EqE=$row['Score_Set3_Ext'];
                    $S4EqE=$row['Score_Set4_Ext'];
                    $S5EqE=$row['Score_Set5_Ext'];
                    
                }
                
?>
<center style=" background: -webkit-linear-gradient(top,yellow,orange); border-radius: 0 0 10px 10px;">
    <br>
    <h4><font color="blue">Ici vous pouvez saisir les scores obtenus lors de ce match</font></h4>
    <form name="myform" id="myform" method="POST" action="javascript:SaisieScoreMatchEquipe(document.getElementById('myform'));">
        <input type="hidden" id="id_Match" value="<?php echo $match; ?>"/>
        <div class="tableau">
        <table cellspacing="0">
            <tr>
                <td>Match</td>
               <td><a id="Eq1"><?php echo $Equipe1; ?></a><br>Mail: <?php echo $MailEquipe1; ?></td>
                       
                <td><a id="Eq2"><?php echo $Equipe2; ?></a><br>Mail: <?php echo $MailEquipe2; ?></td>
                
                <td>Du: <input type="date"  value="<?php echo $Date; ?>" class="log" id="DateMatch" name="DateMatch"><br>
                
                    Lieu du match:
                    <select name="ListePlage" id="ListePlage" class="liste" style="width:130px;" >
                            <?php echo "<option value='".$plage."'>".$plage."</option>"; ?>
                    </select>
                </td>
             </tr>
             <tr>
                 <td>Score Set-1 </td>
                 <td>
                     <select name="scoreS1Eq1" id="scoreS1Eq1" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S1EqD)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                 <td>
                     <select name="scoreS1Eq2" id="scoreS1Eq2" class="liste" onchange="ResultatScoreMatchEquipe()">
                         <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S1EqE)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>

                     </select>
                 </td>
                 <td><a id="gagnantS1"></a></td>
             </tr>
             
             <tr>
                 <td>Score Set-2</td>
                  <td>
                     <select name="scoreS2Eq1" id="scoreS2Eq1" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S2EqD)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                  <td>
                     <select name="scoreS2Eq2" id="scoreS2Eq2" class="liste" onchange="ResultatScoreMatchEquipe()" >
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                            if($i == $S2EqE)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                 <td><a id="gagnantS2"></a></td>
             </tr>
             
              <tr>
                 <td>Score Set-3</td>
                  <td>
                     <select name="scoreS3Eq1" id="scoreS3Eq1" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S3EqD)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                  <td>
                     <select name="scoreS3Eq2" id="scoreS3Eq2" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S3EqE)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                 <td><a id="gagnantS3"></a></td>
             </tr>
              
             <tr>
                 <td>Score Set-4</td>
                  <td>
                     <select name="scoreS4Eq1" id="scoreS4Eq1" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S4EqD)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                  <td>
                     <select name="scoreS4Eq2" id="scoreS4Eq2" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                            if($i == $S4EqE)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                 <td><a id="gagnantS4"></a></td>
             </tr>
            
             <tr>
                 <td>Score Set-5</td>
                  <td>
                     <select name="scoreS5Eq1" id="scoreS5Eq1" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                             if($i == $S5EqD)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                  <td>
                     <select name="scoreS5Eq2" id="scoreS5Eq2" class="liste" onchange="ResultatScoreMatchEquipe()">
                        <?php
                         for($i=0; $i<36; $i++)
                         {
                            if($i == $S5EqE)
                                 echo"<option value='".$i."' selected>".$i."</option>";
                             else
                                echo"<option value='".$i."'>".$i."</option>";
                         }
                         ?>
                           
                     </select>
                 </td>
                 <td><a id="gagnantS5"></a></td>
             </tr>
             <tr>
                 <td>Total des points:</td>
                 <td><a id="resultatsTotEq1"></a></td>
                 <td><a id="resultatsTotEq2"></a></td>
                 <td></td>
             </tr>

        </table>
            </div>
        
        <br>
        <h2>Vainqueur: <font color="Green"><a id="vainqueur"></a></font></h2>
        <input type="submit" value="Valider" class="bouton"/>
   
        <style onload="ResultatScoreMatchEquipe()"></style>
   
          </form>
  


  <?php } ?>
  </center>